const HtmlWebpackPlugin = require('html-webpack-plugin');
const rootDir = process.cwd();
const path = require('path');

const HtmlRouterConfig = require('./config/htmlWebpackConfig')
const htmlRouterConfig = new HtmlRouterConfig()

module.exports = {
    devtool: 'eval-cheap-module-source-map',
    entry: {
        ...htmlRouterConfig.entryConfig(),
    },
    output: {
        path: __dirname + '/dist',
        filename: '[name].js'
    },
    plugins: [
        ...htmlRouterConfig.pluginConfig(),
    ],
    module: {
        rules: [
            {
                test: /\.pug$/,
                use: ['raw-loader', 'pug-html-loader']
            },
            {
                test: /\.(sc|c)ss$/,
                use: ['style-loader', 'css-loader', 'sass-loader']
            }
        ]
    },
    devServer: {
        // port: '3001', // 默认是 8080
        hot: true,
        // stats: 'errors-only', // 终端仅打印 error
        static: {
            directory: path.join(rootDir, './public'),
        },
        client: {
            progress: true,
            // 报错时浏览器全屏覆盖
            overlay: true,
        },
        compress: true, // 是否启用 gzip 压缩
    }
};
